package com.cqupt.scanning.system.file.helper.fft;

import static com.cqupt.scanning.system.file.helper.fft.FFT.fft;

/**
 * @Author 罗倩
 * @Date 2021/10/28 20:32
 */
public class Test {

    // display an array of Complex numbers to standard output
    public static void show(Complex[] x, String title) {
        System.out.println(title);
        System.out.println("-------------------");
        for (int i = 0; i < x.length; i++) {
            System.out.println(x[i]);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        //int N = Integer.parseInt(args[0]);
        int N = 256;
        float SAMPLE_RATE = 10000.0f;  //采样率为10Kz
        Complex[] v = new Complex[N];

        // original data
        for (int k = 0; k < N; k++) {
           v[k] = new Complex(1*Math.sin(2*Math.PI*500*k/SAMPLE_RATE)+(0.5*Math.sin(2*Math.PI*2000*k/SAMPLE_RATE)),0);
           // 1*Math.sin(2*Math.PI*500*k/SAMPLE_RATE)+(0.5*Math.sin(2*Math.PI*2000*k/SAMPLE_RATE))
        }
        show(v,"v");


//        // original data
//        for (int i = 0; i < N; i++) {
//            x[i] = new Complex(i, 0);
//            x[i] = new Complex(-2 * Math.random() + 1, 0);
//        }
//        show(x, "x");

        // FFT of original data
        Complex[] y = fft(v);
        show(y, "y = fft(v)");

        System.out.println("z = |y|");
        System.out.println("------------------");
        for (int k = 0; k < N; k++) {
            //double z = Math.sqrt(y[k].re() * y[k].re() + y[k].im() * y[k].im());
            System.out.println(Math.sqrt(y[k].re() * y[k].re() + y[k].im() * y[k].im()));

        }


    }
}


